package com.gitee.xiao.check;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wang xiao
 * date 2024/7/10
 */
@RestController
public class FaceRecognitionController {
    @Autowired
    private FaceDetectionHandler faceDetectionHandler; // 注入WebSocket消息处理器

    private RedisProperties.Jedis jedis = new RedisProperties.Jedis("localhost");

    @PostMapping("/recognize")
    public void recognizeFace(@RequestBody FaceRecognitionRequest request) {
        // 假设FaceRecognitionService进行了人脸识别
        String recognizedPerson = FaceRecognitionService.recognize(request.getImageBase64());

        // 更新 Redis 中的识别结果
        jedis.set("recognizedPerson", recognizedPerson);

        // 通过 WebSocket 推送识别结果
        faceDetectionHandler.sendFaceRecognitionResult(recognizedPerson);
    }
}
